//
//  TodayEarningsTableHeaderView.m
//  NewPro
//
//  Created by RYX on 2019/1/8.
//  Copyright © 2019 何荧红. All rights reserved.
//

#import "NewTodayEarningsTableHeaderView.h"
#import "TodayEarningsModel.h"

@interface NewTodayEarningsTableHeaderView ()

// 交易总额
@property (weak, nonatomic) IBOutlet UILabel *totalAmountLa;

// 分润收益
@property (weak, nonatomic) IBOutlet UILabel *dividedIncomeLa;

// 激活奖励
@property (weak, nonatomic) IBOutlet UILabel *activeRewardLa;

// 活跃商户
@property (weak, nonatomic) IBOutlet UILabel *activeMerchantLa;

//循环送机器总数
@property (weak, nonatomic) IBOutlet UILabel *TotalCount;

//mp70
@property (weak, nonatomic) IBOutlet UILabel *MP70Count;

//mp70扫码
@property (weak, nonatomic) IBOutlet UILabel *MP702Count;

//h9
@property (weak, nonatomic) IBOutlet UILabel *H9Count;

//h9扫码
@property (weak, nonatomic) IBOutlet UILabel *H92Count;

@property (nonatomic,strong) UIView *xibView;

@end

@implementation NewTodayEarningsTableHeaderView

- (UIView *)xibView{
    
    if (!_xibView) {
        
        _xibView = [[[NSBundle mainBundle] loadNibNamed:@"NewTodayEarningsTableHeaderView" owner:self options:nil] objectAtIndex:0];
    }
    
    return _xibView;
}

- (instancetype)initWithFrame:(CGRect)frame{
    
    self = [super initWithFrame:frame];
    
    if (self) {
        
        [self setUI:frame];
        
    }
    
    return self;
    
}

- (void)setUI:(CGRect)frame{
    
    [self addSubview:self.xibView];
    
    self.xibView.frame = frame;
}

- (void)setModel:(TodayEarningsModel *)model{
    
    self.totalAmountLa.text = model.totalAmount;
    self.dividedIncomeLa.text = model.dividedIncome;
    self.activeRewardLa.text = model.activeReward;
    self.activeMerchantLa.text = model.activeMerchant;
    
}
- (void)setAllPOS:(NSArray *)AllPOS{
    _AllPOS = AllPOS;
    if (_AllPOS.count > 0) {
        NSInteger count = 0;
        for (NSDictionary *dic in _AllPOS) {
            count += [[NSString stringWithFormat:@"%@",dic[@"count"]] integerValue];
            if ([dic[@"label"] isEqualToString:@"MP70"]) {
                self.MP70Count.text = [NSString stringWithFormat:@"%@",dic[@"count"]];
            }
            if ([dic[@"label"] isEqualToString:@"MP70扫码"]) {
                self.MP702Count.text = [NSString stringWithFormat:@"%@",dic[@"count"]];
            }
            if ([dic[@"label"] isEqualToString:@"H9"]) {
                self.H9Count.text = [NSString stringWithFormat:@"%@",dic[@"count"]];
            }
            if ([dic[@"label"] isEqualToString:@"H9扫码"]) {
                self.H92Count.text = [NSString stringWithFormat:@"%@",dic[@"count"]];
            }
        }
        self.TotalCount.text = [NSString stringWithFormat:@"%ld",(long)count];
    }
}

#pragma mark - 点击日历
- (IBAction)onCalendarBtn:(UIButton *)sender {
    
    if (self.delegate && [self.delegate respondsToSelector:@selector(onCalendarBtn)]) {
        
        [self.delegate onCalendarBtn];
    }
}

#pragma mark - 查询
- (IBAction)onSearchBtn:(UIButton *)sender {
    
    if (self.currentTimeLa.text.length <= 0) {
        
        return;
    }
    
    if (self.delegate && [self.delegate respondsToSelector:@selector(onSearchBtn)]) {
        
        [self.delegate onSearchBtn];
    }
    
}

@end
